package ShareYourWay.webpages;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;
import org.hibernate.Session;

import ShareYourWay.functions.App;
import ShareYourWay.project.Meetup;
import ShareYourWay.project.User;
import ShareYourWay.util.AuthPage;
import ShareYourWay.util.HibernateUtil;

public class Register extends AuthPage {

	private static final long serialVersionUID = 1L;
	public Register()
	{
		final User user = new User();
		final App app = new App();
		Form <User> FormRegister = new Form <User> ("form-register");
		
		TextField<String> tname = new TextField<String>("tname", new PropertyModel<String>(user, "name"));
		tname.setRequired(true);
		
		TextField<String> tsurname = new TextField<String>("tsurname", new PropertyModel<String>(user, "surname"));
		tsurname.setRequired(true);
		
		TextField<String> tpassword = new TextField<String>("tpassword", new PropertyModel<String>(user, "password"));
		tpassword.setRequired(true);
		
		TextField<String> tnick = new TextField<String>("tnick", new PropertyModel<String>(user, "nick"));
		tnick.setRequired(true);
		TextField<String> tmail = new TextField<String>("tmail", new PropertyModel<String>(user, "mail"));
		tmail.setRequired(true);
		
		
		 AjaxButton ButtonsaveUser = new AjaxButton("saveuser") {

	            /**
				 * 
				 */
				private static final long serialVersionUID = 1L;

				@Override
	            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
	                // TODO Auto-generated method stub
	            	
	            	// TODO Auto-generated method stub
					User usr = new User (user); // Hago una copia del objeto, si no lo hago se sobreescribirá.
									
					// ID aleatorio (Provisional).
					//usr.setId(3);
					System.out.println("Estoy en registro");
					System.out.println(usr.getName());
					
					app.addUser(usr);
					
//					app.Listar();
//					target.add(MeetPanel);
//					target.appendJavaScript("cerrar_modal(); alertas('Evento creado');");
					

	            }

	        };
	        
	        
	       
	        
	        
	        add(FormRegister);
	        FormRegister.add(tname);
	        FormRegister.add(tsurname);
	        FormRegister.add(tpassword);
	        FormRegister.add(tmail);
	        FormRegister.add(tnick);
	        FormRegister.add(ButtonsaveUser);
	       
		
	}

}
